package com.cloudsigns.factorymanager2.produce.presenter;

import android.os.Handler;

import com.cloudsigns.factorymanager2.produce.bean.Produce_ProductBean;
import com.cloudsigns.factorymanager2.produce.iview.IGetProductOrderEditListView;
import com.cloudsigns.factorymanager2.produce.model.GetProductOrderEditListModel;
import com.cloudsigns.factorymanager2.produce.model.IGetProductOrderEditListModel;

import java.util.List;

public class GetProductOrderEditListPresenter {
    private IGetProductOrderEditListView view;
    private IGetProductOrderEditListModel model;
    private Handler mHandler = new Handler();

    public GetProductOrderEditListPresenter(IGetProductOrderEditListView iView) {
        this.view = iView;
        this.model = new GetProductOrderEditListModel();
    }

    public void getProductOrderEditList() {
        view.showLoading();

        model.getProductOrderList(new GetProductOrderEditListModel.OnProductOrderEditListListener() {
            @Override
            public void getDataSuccessed(final List<Produce_ProductBean> productOrderBeanList) {
                mHandler.post(new Runnable() {
                    @Override
                    public void run() {
                        view.getDataSuccessed(productOrderBeanList);
                        view.hideLoading();
                    }
                });
            }

            @Override
            public void getDataFailed(final String desc) {
                mHandler.post(new Runnable() {
                    @Override
                    public void run() {
                        view.showFailedError(desc);
                        view.hideLoading();
                    }
                });
            }
        });
    }
}
